import React, { Fragment, useRef } from 'react'
import './index.scss'

function AddInput (props) {

  const { isInputShow, addItem } = props;
  let inputRef = useRef()

  const submitValue = () => {
    // console.log(inputRef.current.value);
    const inputVal = inputRef.current.value.trim()
    if (!inputVal) {
      alert('请输入')
      return;
    }
    addItem(inputVal)
    inputRef.current.value = '';
  }

  return (
    <Fragment>
      {
        isInputShow
        ?
        <div className="input-wrapper">
          <input ref={inputRef} type="text" placeholder="请输入待办事件"/>
          <button className="btn btn-primary" onClick={submitValue}>增加</button>
        </div>
        :
        <Fragment></Fragment>
      }
    </Fragment>
  )
}

export default AddInput;